package pl.edu.mimuw.irs.core.model.design.net;

import pl.edu.mimuw.irs.core.global.IDManager;
import pl.edu.mimuw.irs.core.model.design.exception.InternalDesignException;
import pl.edu.mimuw.irs.core.model.design.exception.InternalDesignException.DesignCause;
import pl.edu.mimuw.irs.core.model.petrinet.Arc;
import pl.edu.mimuw.irs.core.model.petrinet.Place;
import pl.edu.mimuw.irs.core.model.petrinet.Transition;

/**
 * @author Jakub Rauch
 * Created on: 2009-05-07
 */
public class IRSArc extends Arc {

	private static final long serialVersionUID = -7803347977458403082L;
	
	// *** Attributes
	
	// *** Constructors
	
	public IRSArc(IDManager idManager, String id, Place place, Transition transition, Direction direction, int weight) {
		super(idManager, id, place, transition, direction, weight);
	}

	public IRSArc(IDManager idManager, Place place, Transition transition, Direction direction, int weight) {
		this(idManager, null, place, transition, direction, weight);
	}
	
	public IRSArc(IDManager idManager, Place place, Transition transition, int weight) {
		this(idManager, place, transition, Direction.PLACE_TRANSITION, weight);
	}
	
	public IRSArc(IDManager idManager, Transition transition, Place place, int weight) {
		this(idManager, place, transition, Direction.TRANSITION_PLACE, weight);
	}
	
	public IRSArc(IDManager idManager, Place place, Transition transition) {
		this(idManager, place, transition, 1);
	}
	
	public IRSArc(IDManager idManager, Transition transition, Place place) {
		this(idManager, transition, place, 1);
	}
	
	public IRSArc(IDManager idManager, Place place) {
		this(idManager, place, null, 1);
	}
	
	public IRSArc(IDManager idManager, Transition transition) {
		this(idManager, transition, null, 1);
	}
	
	// *** Methods

	public IRSArc copy(IRSNode node1,
			IRSNode node2) {
		if (node1 instanceof IRSPlace && node2 instanceof IRSTransition) {
			IRSPlace place = (IRSPlace) node1;
			IRSTransition transition = (IRSTransition) node2;
			IRSArc arc = new IRSArc(getIdManager(), place, transition, getWeight());
			arc.setVertices(getVertices());
			return arc;
		} else if (node1 instanceof IRSTransition && node2 instanceof IRSPlace) {
			IRSTransition transition = (IRSTransition) node1;
			IRSPlace place = (IRSPlace) node2;
			IRSArc arc = new IRSArc(getIdManager(), transition, place, getWeight());
			arc.setVertices(getVertices());
			return arc;
		} else {
			throw new InternalDesignException(DesignCause.NOT_ALLOWED_ARC_NODES, 
					node1.toString(), 
					node2.toString());
		}
	}
}
